home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / AOCE Sample Code / Interprogram Messaging Manager / IPM MessageBoard / statusdialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  6.0 KB  |  304 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * IPM MessageBoard AOCE Sample
  4.  *
  5.  * ©1992-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * commands.c -- called in response to menu commands or appleevents
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        2/12/93        1.0b1        udpate to AOCE beta seed
  14.  * SJF        11/6/91        1.0d1        initial coding
  15.  *
  16.  */
  17.  
  18. #ifndef __TYPES__
  19. #include <Types.h>
  20. #endif
  21.  
  22. #ifndef __QUICKDRAW__
  23. #include <QuickDraw.h>
  24. #endif
  25.  
  26. #ifndef __LISTS__
  27. #include <Lists.h>
  28. #endif
  29.  
  30. #ifndef __WINDOWS__
  31. #include <Windows.h>
  32. #endif
  33.  
  34. #ifndef __DIALOGS__
  35. #include <Dialogs.h>
  36. #endif
  37.  
  38. #ifndef __EVENTS__
  39. #include <Events.h>
  40. #endif
  41.  
  42. #include "const.h"
  43. #include "mymenus.h"
  44. #include "globals.h"
  45. #include "utils.h"
  46. #include "commands.h"
  47. #include "myipm.h"
  48.  
  49. #include "statusdialog.h"
  50.  
  51.  
  52. /* macros */
  53.  
  54. #define GetDlogData(dlog)    ((DlogDataPtr)GetWRefCon((WindowPtr)dlog))
  55.  
  56.  
  57. /*    init our dialog */
  58.  
  59. void MakeMainDialog(void)
  60. {
  61.     Rect iRect;
  62.     Handle iHndl;
  63.     short iType;
  64.     DlogDataPtr dlogData;
  65.     Rect dataBounds;
  66.     Point cellSize = {0,0};
  67.     
  68.     dlogData = (DlogDataPtr) NewPtr(sizeof(DlogData));
  69.     if (MemError()!=noErr) {
  70.         DoError(MemError());
  71.         ExitToShell();
  72.     }
  73.     
  74.     gMainDialog = GetNewDialog(kStatusBoxID,nil,kInFront);
  75.     SetPort(gMainDialog);
  76.     SetRect(&dataBounds,0,0,1,0);
  77.     
  78.     GetDItem(gMainDialog,kMsgListDItem,&iType,&iHndl,&iRect);
  79.     SetDItem(gMainDialog,kMsgListDItem,iType,(Handle)DrawScrollList,&iRect);
  80.     dlogData->msgList = LNew(&iRect,&dataBounds,cellSize,0,gMainDialog,true,false,false,true);
  81.     (**(dlogData->msgList)).selFlags |= lOnlyOne;
  82.     
  83.     GetDItem(gMainDialog,kDestListDItem,&iType,&iHndl,&iRect);
  84.     SetDItem(gMainDialog,kDestListDItem,iType,(Handle)DrawScrollList,&iRect);
  85.     dlogData->destList = LNew(&iRect,&dataBounds,cellSize,0,gMainDialog,true,false,false,true);
  86.     (**(dlogData->destList)).selFlags |= lOnlyOne;
  87.  
  88.     GetDItem(gMainDialog,kMsgScrollDItem,&iType,&iHndl,&iRect);
  89.     SetDItem(gMainDialog,kMsgScrollDItem,iType,(Handle)DrawEmptyItem,&iRect);
  90.  
  91.     GetDItem(gMainDialog,kDestScrollDItem,&iType,&iHndl,&iRect);
  92.     SetDItem(gMainDialog,kDestScrollDItem,iType,(Handle)DrawEmptyItem,&iRect);
  93.  
  94.     GetDItem(gMainDialog,kSeparatorDItem,&iType,&iHndl,&iRect);
  95.     SetDItem(gMainDialog,kSeparatorDItem,iType,(Handle)DrawGraySeparator,&iRect);
  96.  
  97.         // turn new selection on
  98.     GetDItem(gMainDialog,kAtalkAddrBtn,&iType,&iHndl,&iRect);
  99.     SetCtlValue((ControlHandle)iHndl,kCtlOn);
  100.  
  101.         // save current selection
  102.     gRadioBtnSelected = kAtalkAddrBtn;
  103.     
  104.     SetWRefCon(gMainDialog,(long)dlogData);
  105. }
  106.  
  107.  
  108. void CloseMainDialog(void)
  109. {
  110.     DisposeDialog(gMainDialog);
  111. }
  112.  
  113.  
  114. pascal void DrawScrollList(DialogPtr theDlg,short item)
  115. {
  116.     ListHandle theList;
  117.     Rect iRect;
  118.     
  119.     theList = GetListFromItem(theDlg,item);
  120.     PenNormal();
  121.  
  122.     iRect = (**theList).rView;
  123.     InsetRect(&iRect,-1,-1);
  124.     FrameRect(&iRect);
  125.     LUpdate(theDlg->visRgn,theList);
  126. }
  127.  
  128.  
  129. pascal void DrawGraySeparator(DialogPtr theDlg,short item)
  130. {
  131.     Rect iRect;
  132.     Handle iHndl;
  133.     short iType;
  134.     PenState thePenState;
  135.  
  136.     GetPenState(&thePenState);
  137.     PenNormal();
  138.     
  139.     GetDItem(theDlg,item,&iType,&iHndl,&iRect);
  140.     FillRect(&iRect,qd.gray);
  141.  
  142.     SetPenState(&thePenState);
  143. }
  144.  
  145.  
  146. pascal void DrawEmptyItem(DialogPtr theDlg,short item)
  147. {
  148.     #pragma unused (theDlg,item)
  149. }
  150.  
  151.  
  152. ListHandle GetListFromItem(DialogPtr theDlg,short item)
  153. {
  154.     DlogDataPtr dlogData;
  155.     
  156.     dlogData = GetDlogData(theDlg);
  157.     
  158.     switch (item) {
  159.         case kMsgListDItem:
  160.             return dlogData->msgList;
  161.             break;
  162.         case kDestListDItem:
  163.             return dlogData->destList;
  164.             break;
  165.         default:
  166.             DoError(kInternalError);
  167.             return nil;
  168.             break;
  169.     }
  170. }
  171.  
  172.  
  173. short GetSelectedMessage(void)
  174. {
  175.     DlogDataPtr dlogData;
  176.     ListHandle theList;
  177.     Cell theCell = {0,0};
  178.     
  179.     dlogData = GetDlogData(gMainDialog);
  180.     theList = dlogData->msgList;
  181.     
  182.     if (LGetSelect(true,&theCell,theList))
  183.         return theCell.v;
  184.     else
  185.         return -1;
  186. }
  187.  
  188.  
  189. short GetSelectedDestination(void)
  190. {
  191.     DlogDataPtr dlogData;
  192.     ListHandle theList;
  193.     Cell theCell = {0,0};
  194.     
  195.     dlogData = GetDlogData(gMainDialog);
  196.     theList = dlogData->destList;
  197.     
  198.     if (LGetSelect(true,&theCell,theList))
  199.         return theCell.v;
  200.     else
  201.         return -1;
  202. }
  203.  
  204.  
  205. void AddItemToList(short msgNum,short whichList)
  206. {
  207.     ListHandle theList;
  208.     
  209.     Cell testCell = {0,0};
  210.     
  211.     theList = GetListFromItem(gMainDialog,whichList);
  212.     LAddRow(1,msgNum,theList);
  213.     EditItemInList(msgNum,whichList);
  214. }
  215.  
  216.  
  217. void EditItemInList(short msgNum,short whichList)
  218. {
  219.     Cell theCell;
  220.     ListHandle theList;
  221.     Str255 destString;
  222.     
  223.     theCell.h = 0;
  224.     theCell.v = msgNum;
  225.     theList = GetListFromItem(gMainDialog,whichList);
  226.     
  227.     if (whichList==kMsgListDItem)
  228.         LSetCell(&gMessageList[msgNum][1],gMessageList[msgNum][0],theCell,theList);
  229.     else {
  230.         GetDestAsString(msgNum,destString);
  231.         LSetCell(&destString[1],destString[0],theCell,theList);
  232.     }
  233. }
  234.  
  235. void HandleButtons(DialogPtr theDlg, short buttonSelected)
  236. {
  237.     Rect iRect;
  238.     Handle iHndl;
  239.     short iType;
  240.  
  241.         // turn current selection off
  242.     GetDItem(theDlg,gRadioBtnSelected,&iType,&iHndl,&iRect);
  243.     SetCtlValue((ControlHandle)iHndl,kCtlOff);
  244.  
  245.         // turn new selection on
  246.     GetDItem(theDlg,buttonSelected,&iType,&iHndl,&iRect);
  247.     SetCtlValue((ControlHandle)iHndl,kCtlOn);
  248.  
  249.         // save current selection
  250.     gRadioBtnSelected = buttonSelected;
  251. }
  252.  
  253.  
  254. /*    handles events important to our dialog
  255. */
  256.  
  257. Boolean HandleDialogEvents(EventRecord *ev)
  258. {
  259.     DialogPtr theDlg;
  260.     short item;
  261.     
  262.     if (!IsDialogEvent(ev))
  263.         return false;
  264.     
  265.     if (DialogSelect(ev,&theDlg,&item)) {
  266.         switch (item) {
  267.             case kSendDItem:
  268.                 CommSendMessage(GetSelectedMessage(),GetSelectedDestination());
  269.                 break;
  270.             case kViewDItem:
  271.                 CommViewMessage(GetSelectedMessage());
  272.                 break;
  273.             case kMakeMsgDItem:
  274.                 CommMakeMessage();
  275.                 break;
  276.             case kMakeDestDItem:
  277.                 CommMakeDestination();
  278.                 break;
  279.             case kMsgScrollDItem:
  280.             case kDestScrollDItem:
  281.                 item -= 2;            // fall thru to list items
  282.             case kMsgListDItem:
  283.             case kDestListDItem:
  284.                 SetPort(theDlg);
  285.                 GlobalToLocal(&ev->where);
  286.                 LClick(ev->where,ev->modifiers,GetListFromItem(theDlg,item));
  287.                 break;
  288.             case kAtalkAddrBtn:
  289.             case kCreateServerQBtn:
  290.             case kOpenServerQBtn:
  291.             case kPrefMsgQBtn:
  292.             case kMailSlotBtn:
  293.                 HandleButtons(theDlg,item);
  294.                 break;
  295.  
  296.         }
  297.         return true;
  298.     }
  299.     
  300.     return false;
  301. }
  302.  
  303.  
  304.